{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=4 fonc=\"仿宋\" color=blue>一、环境准备</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T17:15:53.733807Z",
     "start_time": "2021-07-15T17:15:51.698735Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 1.99 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "import os\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "import matplotlib\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.preprocessing import OneHotEncoder\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import f1_score, classification_report\n",
    "from lightgbm import LGBMClassifier\n",
    "from imblearn.over_sampling import SMOTE\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "\n",
    "np.set_printoptions(suppress=True)\n",
    "pd.set_option('display.width', 180)\n",
    "pd.set_option('display.max_rows', None)\n",
    "pd.set_option('display.max_columns', 100)\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=4 fonc='仿宋' color=blue>二、导入数据</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T17:16:02.832000Z",
     "start_time": "2021-07-15T17:15:56.889929Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 5.93 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "path = os.path.dirname(os.getcwd()) + \"/data/\"\n",
    "\n",
    "def load_cehicle_data(file, encoding='utf-8'):\n",
    "    return pd.read_csv(file, encoding=encoding)\n",
    "\n",
    "for file in os.listdir(path):\n",
    "    if 'train' in file:\n",
    "        train = load_cehicle_data(path + file)\n",
    "    elif 'test' in file:\n",
    "        test = load_cehicle_data(path + file)\n",
    "    else:\n",
    "        pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=4 fonc=\"仿宋\" color=blue>三、查看数据</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T14:43:50.057738Z",
     "start_time": "2021-07-15T14:43:50.011736Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 0 ns\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>main_account_loan_no</th>\n",
       "      <th>main_account_active_loan_no</th>\n",
       "      <th>main_account_overdue_no</th>\n",
       "      <th>main_account_outstanding_loan</th>\n",
       "      <th>main_account_sanction_loan</th>\n",
       "      <th>main_account_disbursed_loan</th>\n",
       "      <th>sub_account_loan_no</th>\n",
       "      <th>sub_account_active_loan_no</th>\n",
       "      <th>sub_account_overdue_no</th>\n",
       "      <th>sub_account_outstanding_loan</th>\n",
       "      <th>sub_account_sanction_loan</th>\n",
       "      <th>sub_account_disbursed_loan</th>\n",
       "      <th>disbursed_amount</th>\n",
       "      <th>asset_cost</th>\n",
       "      <th>branch_id</th>\n",
       "      <th>supplier_id</th>\n",
       "      <th>manufacturer_id</th>\n",
       "      <th>area_id</th>\n",
       "      <th>employee_code_id</th>\n",
       "      <th>mobileno_flag</th>\n",
       "      <th>idcard_flag</th>\n",
       "      <th>Driving_flag</th>\n",
       "      <th>passport_flag</th>\n",
       "      <th>credit_score</th>\n",
       "      <th>main_account_monthly_payment</th>\n",
       "      <th>sub_account_monthly_payment</th>\n",
       "      <th>last_six_month_new_loan_no</th>\n",
       "      <th>last_six_month_defaulted_no</th>\n",
       "      <th>average_age</th>\n",
       "      <th>credit_history</th>\n",
       "      <th>enquirie_no</th>\n",
       "      <th>loan_to_asset_ratio</th>\n",
       "      <th>total_account_loan_no</th>\n",
       "      <th>sub_account_inactive_loan_no</th>\n",
       "      <th>total_inactive_loan_no</th>\n",
       "      <th>main_account_inactive_loan_no</th>\n",
       "      <th>total_overdue_no</th>\n",
       "      <th>total_outstanding_loan</th>\n",
       "      <th>total_sanction_loan</th>\n",
       "      <th>total_disbursed_loan</th>\n",
       "      <th>total_monthly_payment</th>\n",
       "      <th>outstanding_disburse_ratio</th>\n",
       "      <th>main_account_tenure</th>\n",
       "      <th>sub_account_tenure</th>\n",
       "      <th>disburse_to_sactioned_ratio</th>\n",
       "      <th>active_to_inactive_act_ratio</th>\n",
       "      <th>year_of_birth</th>\n",
       "      <th>disbursed_date</th>\n",
       "      <th>Credit_level</th>\n",
       "      <th>employment_type</th>\n",
       "      <th>age</th>\n",
       "      <th>loan_default</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>105691</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>384989</td>\n",
       "      <td>666207</td>\n",
       "      <td>666207</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>31324</td>\n",
       "      <td>68657</td>\n",
       "      <td>0</td>\n",
       "      <td>535</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>645</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>300</td>\n",
       "      <td>8169</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>86</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "      <td>0.456239</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>384989</td>\n",
       "      <td>666207</td>\n",
       "      <td>666207</td>\n",
       "      <td>8169</td>\n",
       "      <td>1.73</td>\n",
       "      <td>81</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>2.50</td>\n",
       "      <td>1968</td>\n",
       "      <td>2019</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>51</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>24938</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>268670</td>\n",
       "      <td>387994</td>\n",
       "      <td>387994</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>53078</td>\n",
       "      <td>65565</td>\n",
       "      <td>1</td>\n",
       "      <td>767</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>959</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>691</td>\n",
       "      <td>2400</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>13</td>\n",
       "      <td>28</td>\n",
       "      <td>0</td>\n",
       "      <td>0.809548</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>268670</td>\n",
       "      <td>387994</td>\n",
       "      <td>387994</td>\n",
       "      <td>2400</td>\n",
       "      <td>1.44</td>\n",
       "      <td>161</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.33</td>\n",
       "      <td>1992</td>\n",
       "      <td>2019</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>104389</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3519013</td>\n",
       "      <td>3613854</td>\n",
       "      <td>3576048</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>53639</td>\n",
       "      <td>67501</td>\n",
       "      <td>56</td>\n",
       "      <td>138</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2766</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>832</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>55</td>\n",
       "      <td>0</td>\n",
       "      <td>0.794640</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3519013</td>\n",
       "      <td>3613854</td>\n",
       "      <td>3576048</td>\n",
       "      <td>0</td>\n",
       "      <td>1.02</td>\n",
       "      <td>3576048</td>\n",
       "      <td>0</td>\n",
       "      <td>0.99</td>\n",
       "      <td>3.00</td>\n",
       "      <td>1991</td>\n",
       "      <td>2019</td>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>28</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>54688</td>\n",
       "      <td>43</td>\n",
       "      <td>13</td>\n",
       "      <td>6</td>\n",
       "      <td>1867106</td>\n",
       "      <td>2484678</td>\n",
       "      <td>2486856</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>62513</td>\n",
       "      <td>75661</td>\n",
       "      <td>50</td>\n",
       "      <td>211</td>\n",
       "      <td>2</td>\n",
       "      <td>16</td>\n",
       "      <td>1415</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>464</td>\n",
       "      <td>4320912</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>19</td>\n",
       "      <td>91</td>\n",
       "      <td>0</td>\n",
       "      <td>0.826225</td>\n",
       "      <td>43</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>6</td>\n",
       "      <td>1867106</td>\n",
       "      <td>2484678</td>\n",
       "      <td>2486856</td>\n",
       "      <td>4320912</td>\n",
       "      <td>1.33</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.42</td>\n",
       "      <td>1964</td>\n",
       "      <td>2019</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>55</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>63894</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>34439</td>\n",
       "      <td>62616</td>\n",
       "      <td>6</td>\n",
       "      <td>216</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>1186</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.550003</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1995</td>\n",
       "      <td>2019</td>\n",
       "      <td>-1</td>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   customer_id  main_account_loan_no  main_account_active_loan_no  main_account_overdue_no  main_account_outstanding_loan  main_account_sanction_loan  \\\n",
       "0       105691                     4                            3                        0                         384989                      666207   \n",
       "1        24938                     7                            2                        0                         268670                      387994   \n",
       "2       104389                     5                            4                        1                        3519013                     3613854   \n",
       "3        54688                    43                           13                        6                        1867106                     2484678   \n",
       "4        63894                     0                            0                        0                              0                           0   \n",
       "\n",
       "   main_account_disbursed_loan  sub_account_loan_no  sub_account_active_loan_no  sub_account_overdue_no  sub_account_outstanding_loan  sub_account_sanction_loan  \\\n",
       "0                       666207                    0                           0                       0                             0                          0   \n",
       "1                       387994                    0                           0                       0                             0                          0   \n",
       "2                      3576048                    0                           0                       0                             0                          0   \n",
       "3                      2486856                    0                           0                       0                             0                          0   \n",
       "4                            0                    0                           0                       0                             0                          0   \n",
       "\n",
       "   sub_account_disbursed_loan  disbursed_amount  asset_cost  branch_id  supplier_id  manufacturer_id  area_id  employee_code_id  mobileno_flag  idcard_flag  Driving_flag  \\\n",
       "0                           0             31324       68657          0          535                2        0               645              1            1             0   \n",
       "1                           0             53078       65565          1          767                1        1               959              1            1             0   \n",
       "2                           0             53639       67501         56          138                2        3              2766              1            1             0   \n",
       "3                           0             62513       75661         50          211                2       16              1415              1            1             0   \n",
       "4                           0             34439       62616          6          216                2        4              1186              1            1             0   \n",
       "\n",
       "   passport_flag  credit_score  main_account_monthly_payment  sub_account_monthly_payment  last_six_month_new_loan_no  last_six_month_defaulted_no  average_age  credit_history  \\\n",
       "0              0           300                          8169                            0                           0                            0           86              18   \n",
       "1              0           691                          2400                            0                           1                            0           13              28   \n",
       "2              0           832                             0                            0                           1                            0           27              55   \n",
       "3              0           464                       4320912                            0                           7                            4           19              91   \n",
       "4              0             0                             0                            0                           0                            0            0               0   \n",
       "\n",
       "   enquirie_no  loan_to_asset_ratio  total_account_loan_no  sub_account_inactive_loan_no  total_inactive_loan_no  main_account_inactive_loan_no  total_overdue_no  \\\n",
       "0            0             0.456239                      4                             1                       0                              1                 0   \n",
       "1            0             0.809548                      7                             5                       0                              5                 0   \n",
       "2            0             0.794640                      5                             1                       0                              1                 1   \n",
       "3            0             0.826225                     43                            30                       0                             30                 6   \n",
       "4            1             0.550003                      0                             0                       0                              0                 0   \n",
       "\n",
       "   total_outstanding_loan  total_sanction_loan  total_disbursed_loan  total_monthly_payment  outstanding_disburse_ratio  main_account_tenure  sub_account_tenure  \\\n",
       "0                  384989               666207                666207                   8169                        1.73                   81                   0   \n",
       "1                  268670               387994                387994                   2400                        1.44                  161                   0   \n",
       "2                 3519013              3613854               3576048                      0                        1.02              3576048                   0   \n",
       "3                 1867106              2484678               2486856                4320912                        1.33                    0                   0   \n",
       "4                       0                    0                     0                      0                        1.00                    0                   0   \n",
       "\n",
       "   disburse_to_sactioned_ratio  active_to_inactive_act_ratio  year_of_birth  disbursed_date  Credit_level  employment_type  age  loan_default  \n",
       "0                         1.00                          2.50           1968            2019             1                0   51             0  \n",
       "1                         1.00                          1.33           1992            2019             9                0   27             0  \n",
       "2                         0.99                          3.00           1991            2019            13                1   28             0  \n",
       "3                         1.00                          1.42           1964            2019             3                1   55             0  \n",
       "4                         1.00                          1.00           1995            2019            -1                0   24             0  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "train.head()、"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T14:43:52.093840Z",
     "start_time": "2021-07-15T14:43:52.051838Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 0 ns\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>main_account_loan_no</th>\n",
       "      <th>main_account_active_loan_no</th>\n",
       "      <th>main_account_overdue_no</th>\n",
       "      <th>main_account_outstanding_loan</th>\n",
       "      <th>main_account_sanction_loan</th>\n",
       "      <th>main_account_disbursed_loan</th>\n",
       "      <th>sub_account_loan_no</th>\n",
       "      <th>sub_account_active_loan_no</th>\n",
       "      <th>sub_account_overdue_no</th>\n",
       "      <th>sub_account_outstanding_loan</th>\n",
       "      <th>sub_account_sanction_loan</th>\n",
       "      <th>sub_account_disbursed_loan</th>\n",
       "      <th>disbursed_amount</th>\n",
       "      <th>asset_cost</th>\n",
       "      <th>branch_id</th>\n",
       "      <th>supplier_id</th>\n",
       "      <th>manufacturer_id</th>\n",
       "      <th>area_id</th>\n",
       "      <th>employee_code_id</th>\n",
       "      <th>mobileno_flag</th>\n",
       "      <th>idcard_flag</th>\n",
       "      <th>Driving_flag</th>\n",
       "      <th>passport_flag</th>\n",
       "      <th>credit_score</th>\n",
       "      <th>main_account_monthly_payment</th>\n",
       "      <th>sub_account_monthly_payment</th>\n",
       "      <th>last_six_month_new_loan_no</th>\n",
       "      <th>last_six_month_defaulted_no</th>\n",
       "      <th>average_age</th>\n",
       "      <th>credit_history</th>\n",
       "      <th>enquirie_no</th>\n",
       "      <th>loan_to_asset_ratio</th>\n",
       "      <th>total_account_loan_no</th>\n",
       "      <th>sub_account_inactive_loan_no</th>\n",
       "      <th>total_inactive_loan_no</th>\n",
       "      <th>main_account_inactive_loan_no</th>\n",
       "      <th>total_overdue_no</th>\n",
       "      <th>total_outstanding_loan</th>\n",
       "      <th>total_sanction_loan</th>\n",
       "      <th>total_disbursed_loan</th>\n",
       "      <th>total_monthly_payment</th>\n",
       "      <th>outstanding_disburse_ratio</th>\n",
       "      <th>main_account_tenure</th>\n",
       "      <th>sub_account_tenure</th>\n",
       "      <th>disburse_to_sactioned_ratio</th>\n",
       "      <th>active_to_inactive_act_ratio</th>\n",
       "      <th>year_of_birth</th>\n",
       "      <th>disbursed_date</th>\n",
       "      <th>Credit_level</th>\n",
       "      <th>employment_type</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>14342</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>75804</td>\n",
       "      <td>57000</td>\n",
       "      <td>75804</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>48349</td>\n",
       "      <td>65217</td>\n",
       "      <td>26</td>\n",
       "      <td>602</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>735</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>300</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>109</td>\n",
       "      <td>1</td>\n",
       "      <td>0.741356</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>75804</td>\n",
       "      <td>57000</td>\n",
       "      <td>75804</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>75804</td>\n",
       "      <td>0</td>\n",
       "      <td>1.33</td>\n",
       "      <td>1.25</td>\n",
       "      <td>1976</td>\n",
       "      <td>2019</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>94753</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>50503</td>\n",
       "      <td>66416</td>\n",
       "      <td>16</td>\n",
       "      <td>123</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>131</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.760404</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1970</td>\n",
       "      <td>2019</td>\n",
       "      <td>-1</td>\n",
       "      <td>1</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>140283</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>68623</td>\n",
       "      <td>100800</td>\n",
       "      <td>14</td>\n",
       "      <td>395</td>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>450</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.680784</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1997</td>\n",
       "      <td>2019</td>\n",
       "      <td>-1</td>\n",
       "      <td>1</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>134742</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>42100</td>\n",
       "      <td>90186</td>\n",
       "      <td>90186</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>56513</td>\n",
       "      <td>69300</td>\n",
       "      <td>6</td>\n",
       "      <td>506</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2108</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>738</td>\n",
       "      <td>8540</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>19</td>\n",
       "      <td>0</td>\n",
       "      <td>0.815483</td>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>42100</td>\n",
       "      <td>90186</td>\n",
       "      <td>90186</td>\n",
       "      <td>8540</td>\n",
       "      <td>2.14</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>2.33</td>\n",
       "      <td>1977</td>\n",
       "      <td>2019</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4749</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>40104</td>\n",
       "      <td>68800</td>\n",
       "      <td>4</td>\n",
       "      <td>789</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>986</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.582907</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1984</td>\n",
       "      <td>2019</td>\n",
       "      <td>-1</td>\n",
       "      <td>0</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   customer_id  main_account_loan_no  main_account_active_loan_no  main_account_overdue_no  main_account_outstanding_loan  main_account_sanction_loan  \\\n",
       "0        14342                     4                            1                        3                          75804                       57000   \n",
       "1        94753                     0                            0                        0                              0                           0   \n",
       "2       140283                     0                            0                        0                              0                           0   \n",
       "3       134742                     6                            4                        0                          42100                       90186   \n",
       "4         4749                     0                            0                        0                              0                           0   \n",
       "\n",
       "   main_account_disbursed_loan  sub_account_loan_no  sub_account_active_loan_no  sub_account_overdue_no  sub_account_outstanding_loan  sub_account_sanction_loan  \\\n",
       "0                        75804                    0                           0                       0                             0                          0   \n",
       "1                            0                    0                           0                       0                             0                          0   \n",
       "2                            0                    0                           0                       0                             0                          0   \n",
       "3                        90186                    0                           0                       0                             0                          0   \n",
       "4                            0                    0                           0                       0                             0                          0   \n",
       "\n",
       "   sub_account_disbursed_loan  disbursed_amount  asset_cost  branch_id  supplier_id  manufacturer_id  area_id  employee_code_id  mobileno_flag  idcard_flag  Driving_flag  \\\n",
       "0                           0             48349       65217         26          602                2        5               735              1            1             0   \n",
       "1                           0             50503       66416         16          123                2        2               131              1            1             0   \n",
       "2                           0             68623      100800         14          395                2        8               450              1            1             0   \n",
       "3                           0             56513       69300          6          506                2        4              2108              1            1             0   \n",
       "4                           0             40104       68800          4          789                5        5               986              1            1             0   \n",
       "\n",
       "   passport_flag  credit_score  main_account_monthly_payment  sub_account_monthly_payment  last_six_month_new_loan_no  last_six_month_defaulted_no  average_age  credit_history  \\\n",
       "0              0           300                             0                            0                           0                            0           40             109   \n",
       "1              0             0                             0                            0                           0                            0            0               0   \n",
       "2              0             0                             0                            0                           0                            0            0               0   \n",
       "3              0           738                          8540                            0                           1                            0            1              19   \n",
       "4              0             0                             0                            0                           0                            0            0               0   \n",
       "\n",
       "   enquirie_no  loan_to_asset_ratio  total_account_loan_no  sub_account_inactive_loan_no  total_inactive_loan_no  main_account_inactive_loan_no  total_overdue_no  \\\n",
       "0            1             0.741356                      4                             3                       0                              3                 3   \n",
       "1            0             0.760404                      0                             0                       0                              0                 0   \n",
       "2            1             0.680784                      0                             0                       0                              0                 0   \n",
       "3            0             0.815483                      6                             2                       0                              2                 0   \n",
       "4            0             0.582907                      0                             0                       0                              0                 0   \n",
       "\n",
       "   total_outstanding_loan  total_sanction_loan  total_disbursed_loan  total_monthly_payment  outstanding_disburse_ratio  main_account_tenure  sub_account_tenure  \\\n",
       "0                   75804                57000                 75804                      0                        1.00                75804                   0   \n",
       "1                       0                    0                     0                      0                        1.00                    0                   0   \n",
       "2                       0                    0                     0                      0                        1.00                    0                   0   \n",
       "3                   42100                90186                 90186                   8540                        2.14                   10                   0   \n",
       "4                       0                    0                     0                      0                        1.00                    0                   0   \n",
       "\n",
       "   disburse_to_sactioned_ratio  active_to_inactive_act_ratio  year_of_birth  disbursed_date  Credit_level  employment_type  age  \n",
       "0                         1.33                          1.25           1976            2019             1                0   43  \n",
       "1                         1.00                          1.00           1970            2019            -1                1   49  \n",
       "2                         1.00                          1.00           1997            2019            -1                1   22  \n",
       "3                         1.00                          2.33           1977            2019            11                0   42  \n",
       "4                         1.00                          1.00           1984            2019            -1                0   35  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "test.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=4 fonc=\"仿宋\" color=blue>四、数据预处理</font>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=3 fonc=\"仿宋\" color=green>（一）删除特征</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T17:16:15.337191Z",
     "start_time": "2021-07-15T17:16:15.175183Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 144 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "drop_feature = ['mobileno_flag','idcard_flag','year_of_birth',\n",
    "                'disbursed_date','branch_id','supplier_id',\n",
    "                'employee_code_id']\n",
    "train.drop(drop_feature, axis=1, inplace=True)\n",
    "test.drop(drop_feature, axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=3 fonc=\"仿宋\" color=green>（二）类别特征独热编码</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T17:16:24.269439Z",
     "start_time": "2021-07-15T17:16:22.684379Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 1.58 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "def onehot_model(train):\n",
    "    one_hot = OneHotEncoder(handle_unknown='ignore').fit(train)  # 定义独热编码模型\n",
    "    feature_names = one_hot.get_feature_names(train.columns)  # 将独热编码模型训练后的特征名取出\n",
    "    return one_hot, feature_names\n",
    "\n",
    "def pred_onehot(model, feature_names, pred_dataframe):\n",
    "    return pd.DataFrame(model.transform(pred_dataframe).toarray(),columns=feature_names)\n",
    "\n",
    "columns = ['manufacturer_id', 'area_id', 'Driving_flag', 'passport_flag', 'employment_type']\n",
    "train_categoris = train[columns]\n",
    "test_categoris = test[columns]\n",
    "label = train.pop('loan_default')\n",
    "\n",
    "train.drop(columns, axis=1, inplace=True)\n",
    "test.drop(columns, axis=1, inplace=True)\n",
    "\n",
    "one_hot, feature_names = onehot_model(train_categoris.astype(object))\n",
    "train_onehot = pred_onehot(one_hot, feature_names, train_categoris.astype(object))\n",
    "test_onehot = pred_onehot(one_hot, feature_names, test_categoris.astype(object))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=3 fonc=\"仿宋\" color=green>（三）异常值处理</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T17:16:34.645791Z",
     "start_time": "2021-07-15T17:16:27.384561Z"
    }
   },
   "outputs": [],
   "source": [
    "%%time\n",
    "def ourlier_test(df):\n",
    "    columns = ['main_account_overdue_no', 'sub_account_loan_no', 'sub_account_active_loan_no',\n",
    "               'sub_account_overdue_no', 'sub_account_outstanding_loan', 'sub_account_sanction_loan',\n",
    "               'sub_account_disbursed_loan', 'sub_account_monthly_payment', 'last_six_month_new_loan_no',\n",
    "               'last_six_month_defaulted_no', 'enquirie_no', 'total_inactive_loan_no', \n",
    "               'total_overdue_no', 'sub_account_tenure']\n",
    "    for column in df.columns.tolist()[1:]:\n",
    "        if column in columns:\n",
    "            pass\n",
    "        else:\n",
    "            describe = df[column].describe()\n",
    "            up = describe.loc['75%']\n",
    "            down = describe.loc['25%']\n",
    "            upper = up + 1.5 * (up - down)\n",
    "            lower = down - 1.5 * (up - down)\n",
    "            df.loc[df[column] > upper, column] = upper\n",
    "            df.loc[df[column] < lower, column] = lower\n",
    "    return df\n",
    "\n",
    "train = ourlier_test(train)\n",
    "test = ourlier_test(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T14:33:18.807054Z",
     "start_time": "2021-07-15T14:33:18.304028Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>main_account_loan_no</th>\n",
       "      <th>main_account_active_loan_no</th>\n",
       "      <th>main_account_overdue_no</th>\n",
       "      <th>main_account_outstanding_loan</th>\n",
       "      <th>main_account_sanction_loan</th>\n",
       "      <th>main_account_disbursed_loan</th>\n",
       "      <th>sub_account_loan_no</th>\n",
       "      <th>sub_account_active_loan_no</th>\n",
       "      <th>sub_account_overdue_no</th>\n",
       "      <th>sub_account_outstanding_loan</th>\n",
       "      <th>sub_account_sanction_loan</th>\n",
       "      <th>sub_account_disbursed_loan</th>\n",
       "      <th>disbursed_amount</th>\n",
       "      <th>asset_cost</th>\n",
       "      <th>credit_score</th>\n",
       "      <th>main_account_monthly_payment</th>\n",
       "      <th>sub_account_monthly_payment</th>\n",
       "      <th>last_six_month_new_loan_no</th>\n",
       "      <th>last_six_month_defaulted_no</th>\n",
       "      <th>average_age</th>\n",
       "      <th>credit_history</th>\n",
       "      <th>enquirie_no</th>\n",
       "      <th>loan_to_asset_ratio</th>\n",
       "      <th>total_account_loan_no</th>\n",
       "      <th>sub_account_inactive_loan_no</th>\n",
       "      <th>total_inactive_loan_no</th>\n",
       "      <th>main_account_inactive_loan_no</th>\n",
       "      <th>total_overdue_no</th>\n",
       "      <th>total_outstanding_loan</th>\n",
       "      <th>total_sanction_loan</th>\n",
       "      <th>total_disbursed_loan</th>\n",
       "      <th>total_monthly_payment</th>\n",
       "      <th>outstanding_disburse_ratio</th>\n",
       "      <th>main_account_tenure</th>\n",
       "      <th>sub_account_tenure</th>\n",
       "      <th>disburse_to_sactioned_ratio</th>\n",
       "      <th>active_to_inactive_act_ratio</th>\n",
       "      <th>Credit_level</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.0</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>99944.368847</td>\n",
       "      <td>1.789163</td>\n",
       "      <td>0.717207</td>\n",
       "      <td>0.153427</td>\n",
       "      <td>21756.550093</td>\n",
       "      <td>40229.225813</td>\n",
       "      <td>38971.191273</td>\n",
       "      <td>0.060133</td>\n",
       "      <td>0.027967</td>\n",
       "      <td>0.007293</td>\n",
       "      <td>5.416077e+03</td>\n",
       "      <td>7.385876e+03</td>\n",
       "      <td>7.268286e+03</td>\n",
       "      <td>53897.244167</td>\n",
       "      <td>73903.693587</td>\n",
       "      <td>291.228720</td>\n",
       "      <td>1185.437297</td>\n",
       "      <td>2.938682e+02</td>\n",
       "      <td>0.384900</td>\n",
       "      <td>0.095687</td>\n",
       "      <td>6.974473</td>\n",
       "      <td>11.524987</td>\n",
       "      <td>0.203433</td>\n",
       "      <td>0.725372</td>\n",
       "      <td>1.823537</td>\n",
       "      <td>0.648600</td>\n",
       "      <td>0.032167</td>\n",
       "      <td>0.660150</td>\n",
       "      <td>0.160720</td>\n",
       "      <td>23262.295620</td>\n",
       "      <td>42437.038587</td>\n",
       "      <td>41231.699020</td>\n",
       "      <td>1242.133127</td>\n",
       "      <td>1.152848</td>\n",
       "      <td>15.848337</td>\n",
       "      <td>2.773138e+03</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.369947</td>\n",
       "      <td>3.132360</td>\n",
       "      <td>34.132020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>57629.110557</td>\n",
       "      <td>2.512731</td>\n",
       "      <td>0.957328</td>\n",
       "      <td>0.542496</td>\n",
       "      <td>34782.806156</td>\n",
       "      <td>61513.123332</td>\n",
       "      <td>59625.998690</td>\n",
       "      <td>0.652912</td>\n",
       "      <td>0.325185</td>\n",
       "      <td>0.111236</td>\n",
       "      <td>1.617336e+05</td>\n",
       "      <td>1.742796e+05</td>\n",
       "      <td>1.735824e+05</td>\n",
       "      <td>11231.774791</td>\n",
       "      <td>12467.697086</td>\n",
       "      <td>339.282431</td>\n",
       "      <td>1941.003135</td>\n",
       "      <td>1.304782e+04</td>\n",
       "      <td>0.962877</td>\n",
       "      <td>0.382359</td>\n",
       "      <td>10.186733</td>\n",
       "      <td>16.339854</td>\n",
       "      <td>0.696590</td>\n",
       "      <td>0.108117</td>\n",
       "      <td>2.534893</td>\n",
       "      <td>0.968148</td>\n",
       "      <td>0.429154</td>\n",
       "      <td>0.974787</td>\n",
       "      <td>0.557779</td>\n",
       "      <td>37095.950517</td>\n",
       "      <td>64684.520112</td>\n",
       "      <td>62937.104477</td>\n",
       "      <td>2024.759518</td>\n",
       "      <td>0.259965</td>\n",
       "      <td>24.999053</td>\n",
       "      <td>1.043622e+05</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.537219</td>\n",
       "      <td>5.268384</td>\n",
       "      <td>9.813128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-53188.500000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-5.746470e+05</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>27102.500000</td>\n",
       "      <td>45602.500000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.446774</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-56832.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.610000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>18.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>50069.750000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>46973.000000</td>\n",
       "      <td>65719.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.664456</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>26.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>99887.500000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>53703.000000</td>\n",
       "      <td>70925.000000</td>\n",
       "      <td>14.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.741398</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>32.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>149916.500000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>35459.000000</td>\n",
       "      <td>63600.000000</td>\n",
       "      <td>61508.500000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>60220.000000</td>\n",
       "      <td>79130.000000</td>\n",
       "      <td>680.000000</td>\n",
       "      <td>1989.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.809578</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>37888.000000</td>\n",
       "      <td>66900.000000</td>\n",
       "      <td>65000.000000</td>\n",
       "      <td>2076.000000</td>\n",
       "      <td>1.260000</td>\n",
       "      <td>25.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.670000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>41.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>199716.000000</td>\n",
       "      <td>7.500000</td>\n",
       "      <td>2.500000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>88647.500000</td>\n",
       "      <td>159000.000000</td>\n",
       "      <td>153771.250000</td>\n",
       "      <td>52.000000</td>\n",
       "      <td>36.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>3.603285e+07</td>\n",
       "      <td>2.688820e+07</td>\n",
       "      <td>2.688820e+07</td>\n",
       "      <td>80090.500000</td>\n",
       "      <td>99246.500000</td>\n",
       "      <td>890.000000</td>\n",
       "      <td>4972.500000</td>\n",
       "      <td>3.246710e+06</td>\n",
       "      <td>35.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>32.500000</td>\n",
       "      <td>50.000000</td>\n",
       "      <td>28.000000</td>\n",
       "      <td>0.937987</td>\n",
       "      <td>7.500000</td>\n",
       "      <td>2.500000</td>\n",
       "      <td>42.000000</td>\n",
       "      <td>2.500000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>94720.000000</td>\n",
       "      <td>167250.000000</td>\n",
       "      <td>162500.000000</td>\n",
       "      <td>5190.000000</td>\n",
       "      <td>1.650000</td>\n",
       "      <td>62.500000</td>\n",
       "      <td>1.980000e+07</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.675000</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>63.500000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         customer_id  main_account_loan_no  main_account_active_loan_no  main_account_overdue_no  main_account_outstanding_loan  main_account_sanction_loan  \\\n",
       "count  150000.000000         150000.000000                150000.000000            150000.000000                  150000.000000               150000.000000   \n",
       "mean    99944.368847              1.789163                     0.717207                 0.153427                   21756.550093                40229.225813   \n",
       "std     57629.110557              2.512731                     0.957328                 0.542496                   34782.806156                61513.123332   \n",
       "min         0.000000              0.000000                     0.000000                 0.000000                  -53188.500000                    0.000000   \n",
       "25%     50069.750000              0.000000                     0.000000                 0.000000                       0.000000                    0.000000   \n",
       "50%     99887.500000              1.000000                     0.000000                 0.000000                       0.000000                    0.000000   \n",
       "75%    149916.500000              3.000000                     1.000000                 0.000000                   35459.000000                63600.000000   \n",
       "max    199716.000000              7.500000                     2.500000                23.000000                   88647.500000               159000.000000   \n",
       "\n",
       "       main_account_disbursed_loan  sub_account_loan_no  sub_account_active_loan_no  sub_account_overdue_no  sub_account_outstanding_loan  sub_account_sanction_loan  \\\n",
       "count                150000.000000        150000.000000               150000.000000           150000.000000                  1.500000e+05               1.500000e+05   \n",
       "mean                  38971.191273             0.060133                    0.027967                0.007293                  5.416077e+03               7.385876e+03   \n",
       "std                   59625.998690             0.652912                    0.325185                0.111236                  1.617336e+05               1.742796e+05   \n",
       "min                       0.000000             0.000000                    0.000000                0.000000                 -5.746470e+05               0.000000e+00   \n",
       "25%                       0.000000             0.000000                    0.000000                0.000000                  0.000000e+00               0.000000e+00   \n",
       "50%                       0.000000             0.000000                    0.000000                0.000000                  0.000000e+00               0.000000e+00   \n",
       "75%                   61508.500000             0.000000                    0.000000                0.000000                  0.000000e+00               0.000000e+00   \n",
       "max                  153771.250000            52.000000                   36.000000                7.000000                  3.603285e+07               2.688820e+07   \n",
       "\n",
       "       sub_account_disbursed_loan  disbursed_amount     asset_cost   credit_score  main_account_monthly_payment  sub_account_monthly_payment  last_six_month_new_loan_no  \\\n",
       "count                1.500000e+05     150000.000000  150000.000000  150000.000000                 150000.000000                 1.500000e+05               150000.000000   \n",
       "mean                 7.268286e+03      53897.244167   73903.693587     291.228720                   1185.437297                 2.938682e+02                    0.384900   \n",
       "std                  1.735824e+05      11231.774791   12467.697086     339.282431                   1941.003135                 1.304782e+04                    0.962877   \n",
       "min                  0.000000e+00      27102.500000   45602.500000       0.000000                      0.000000                 0.000000e+00                    0.000000   \n",
       "25%                  0.000000e+00      46973.000000   65719.000000       0.000000                      0.000000                 0.000000e+00                    0.000000   \n",
       "50%                  0.000000e+00      53703.000000   70925.000000      14.000000                      0.000000                 0.000000e+00                    0.000000   \n",
       "75%                  0.000000e+00      60220.000000   79130.000000     680.000000                   1989.000000                 0.000000e+00                    0.000000   \n",
       "max                  2.688820e+07      80090.500000   99246.500000     890.000000                   4972.500000                 3.246710e+06                   35.000000   \n",
       "\n",
       "       last_six_month_defaulted_no    average_age  credit_history    enquirie_no  loan_to_asset_ratio  total_account_loan_no  sub_account_inactive_loan_no  \\\n",
       "count                150000.000000  150000.000000   150000.000000  150000.000000        150000.000000          150000.000000                 150000.000000   \n",
       "mean                      0.095687       6.974473       11.524987       0.203433             0.725372               1.823537                      0.648600   \n",
       "std                       0.382359      10.186733       16.339854       0.696590             0.108117               2.534893                      0.968148   \n",
       "min                       0.000000       0.000000        0.000000       0.000000             0.446774               0.000000                      0.000000   \n",
       "25%                       0.000000       0.000000        0.000000       0.000000             0.664456               0.000000                      0.000000   \n",
       "50%                       0.000000       0.000000        0.000000       0.000000             0.741398               1.000000                      0.000000   \n",
       "75%                       0.000000      13.000000       20.000000       0.000000             0.809578               3.000000                      1.000000   \n",
       "max                      20.000000      32.500000       50.000000      28.000000             0.937987               7.500000                      2.500000   \n",
       "\n",
       "       total_inactive_loan_no  main_account_inactive_loan_no  total_overdue_no  total_outstanding_loan  total_sanction_loan  total_disbursed_loan  total_monthly_payment  \\\n",
       "count           150000.000000                  150000.000000     150000.000000           150000.000000        150000.000000         150000.000000          150000.000000   \n",
       "mean                 0.032167                       0.660150          0.160720            23262.295620         42437.038587          41231.699020            1242.133127   \n",
       "std                  0.429154                       0.974787          0.557779            37095.950517         64684.520112          62937.104477            2024.759518   \n",
       "min                  0.000000                       0.000000          0.000000           -56832.000000             0.000000              0.000000               0.000000   \n",
       "25%                  0.000000                       0.000000          0.000000                0.000000             0.000000              0.000000               0.000000   \n",
       "50%                  0.000000                       0.000000          0.000000                0.000000             0.000000              0.000000               0.000000   \n",
       "75%                  0.000000                       1.000000          0.000000            37888.000000         66900.000000          65000.000000            2076.000000   \n",
       "max                 42.000000                       2.500000         23.000000            94720.000000        167250.000000         162500.000000            5190.000000   \n",
       "\n",
       "       outstanding_disburse_ratio  main_account_tenure  sub_account_tenure  disburse_to_sactioned_ratio  active_to_inactive_act_ratio   Credit_level            age  \n",
       "count               150000.000000        150000.000000        1.500000e+05                     150000.0                 150000.000000  150000.000000  150000.000000  \n",
       "mean                     1.152848            15.848337        2.773138e+03                          1.0                      1.369947       3.132360      34.132020  \n",
       "std                      0.259965            24.999053        1.043622e+05                          0.0                      0.537219       5.268384       9.813128  \n",
       "min                      0.610000             0.000000        0.000000e+00                          1.0                      1.000000      -1.000000      18.000000  \n",
       "25%                      1.000000             0.000000        0.000000e+00                          1.0                      1.000000      -1.000000      26.000000  \n",
       "50%                      1.000000             0.000000        0.000000e+00                          1.0                      1.000000      -1.000000      32.000000  \n",
       "75%                      1.260000            25.000000        0.000000e+00                          1.0                      1.670000       8.000000      41.000000  \n",
       "max                      1.650000            62.500000        1.980000e+07                          1.0                      2.675000      13.000000      63.500000  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T13:46:04.215997Z",
     "start_time": "2021-07-15T13:46:03.799989Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>main_account_loan_no</th>\n",
       "      <th>main_account_active_loan_no</th>\n",
       "      <th>main_account_overdue_no</th>\n",
       "      <th>main_account_outstanding_loan</th>\n",
       "      <th>main_account_sanction_loan</th>\n",
       "      <th>main_account_disbursed_loan</th>\n",
       "      <th>sub_account_loan_no</th>\n",
       "      <th>sub_account_active_loan_no</th>\n",
       "      <th>sub_account_overdue_no</th>\n",
       "      <th>sub_account_outstanding_loan</th>\n",
       "      <th>sub_account_sanction_loan</th>\n",
       "      <th>sub_account_disbursed_loan</th>\n",
       "      <th>disbursed_amount</th>\n",
       "      <th>asset_cost</th>\n",
       "      <th>credit_score</th>\n",
       "      <th>main_account_monthly_payment</th>\n",
       "      <th>sub_account_monthly_payment</th>\n",
       "      <th>last_six_month_new_loan_no</th>\n",
       "      <th>last_six_month_defaulted_no</th>\n",
       "      <th>average_age</th>\n",
       "      <th>credit_history</th>\n",
       "      <th>enquirie_no</th>\n",
       "      <th>loan_to_asset_ratio</th>\n",
       "      <th>total_account_loan_no</th>\n",
       "      <th>sub_account_inactive_loan_no</th>\n",
       "      <th>total_inactive_loan_no</th>\n",
       "      <th>main_account_inactive_loan_no</th>\n",
       "      <th>total_overdue_no</th>\n",
       "      <th>total_outstanding_loan</th>\n",
       "      <th>total_sanction_loan</th>\n",
       "      <th>total_disbursed_loan</th>\n",
       "      <th>total_monthly_payment</th>\n",
       "      <th>outstanding_disburse_ratio</th>\n",
       "      <th>main_account_tenure</th>\n",
       "      <th>sub_account_tenure</th>\n",
       "      <th>disburse_to_sactioned_ratio</th>\n",
       "      <th>active_to_inactive_act_ratio</th>\n",
       "      <th>Credit_level</th>\n",
       "      <th>age</th>\n",
       "      <th>loan_default</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.00000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.499880e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>99944.368847</td>\n",
       "      <td>2.447133</td>\n",
       "      <td>1.045500</td>\n",
       "      <td>0.153427</td>\n",
       "      <td>1.670825e+05</td>\n",
       "      <td>2.225586e+05</td>\n",
       "      <td>2.221730e+05</td>\n",
       "      <td>0.060133</td>\n",
       "      <td>0.027967</td>\n",
       "      <td>0.007293</td>\n",
       "      <td>5.416077e+03</td>\n",
       "      <td>7.385876e+03</td>\n",
       "      <td>7.268286e+03</td>\n",
       "      <td>54238.47824</td>\n",
       "      <td>7.580399e+04</td>\n",
       "      <td>291.228720</td>\n",
       "      <td>1.295898e+04</td>\n",
       "      <td>2.938682e+02</td>\n",
       "      <td>0.384900</td>\n",
       "      <td>0.095687</td>\n",
       "      <td>8.027107</td>\n",
       "      <td>13.128353</td>\n",
       "      <td>0.203433</td>\n",
       "      <td>0.723558</td>\n",
       "      <td>2.507267</td>\n",
       "      <td>1.401633</td>\n",
       "      <td>0.032167</td>\n",
       "      <td>1.433800</td>\n",
       "      <td>0.160720</td>\n",
       "      <td>1.724986e+05</td>\n",
       "      <td>2.299445e+05</td>\n",
       "      <td>2.294413e+05</td>\n",
       "      <td>1.325285e+04</td>\n",
       "      <td>1.391973e+03</td>\n",
       "      <td>5.169842e+04</td>\n",
       "      <td>2.773138e+03</td>\n",
       "      <td>6.506428e+02</td>\n",
       "      <td>1.438740</td>\n",
       "      <td>3.132360</td>\n",
       "      <td>34.132100</td>\n",
       "      <td>0.176967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>57629.110557</td>\n",
       "      <td>5.197172</td>\n",
       "      <td>1.952708</td>\n",
       "      <td>0.542496</td>\n",
       "      <td>9.808619e+05</td>\n",
       "      <td>2.840313e+06</td>\n",
       "      <td>2.844075e+06</td>\n",
       "      <td>0.652912</td>\n",
       "      <td>0.325185</td>\n",
       "      <td>0.111236</td>\n",
       "      <td>1.617336e+05</td>\n",
       "      <td>1.742796e+05</td>\n",
       "      <td>1.735824e+05</td>\n",
       "      <td>12835.46104</td>\n",
       "      <td>1.879745e+04</td>\n",
       "      <td>339.282431</td>\n",
       "      <td>1.508468e+05</td>\n",
       "      <td>1.304782e+04</td>\n",
       "      <td>0.962877</td>\n",
       "      <td>0.382359</td>\n",
       "      <td>13.830386</td>\n",
       "      <td>21.125146</td>\n",
       "      <td>0.696590</td>\n",
       "      <td>0.113621</td>\n",
       "      <td>5.273201</td>\n",
       "      <td>3.924056</td>\n",
       "      <td>0.429154</td>\n",
       "      <td>3.964609</td>\n",
       "      <td>0.557779</td>\n",
       "      <td>9.969156e+05</td>\n",
       "      <td>2.847267e+06</td>\n",
       "      <td>2.850957e+06</td>\n",
       "      <td>1.515095e+05</td>\n",
       "      <td>3.132484e+04</td>\n",
       "      <td>2.614563e+06</td>\n",
       "      <td>1.043622e+05</td>\n",
       "      <td>1.312314e+05</td>\n",
       "      <td>0.789844</td>\n",
       "      <td>5.268384</td>\n",
       "      <td>9.813379</td>\n",
       "      <td>0.381642</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-6.678296e+06</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-5.746470e+05</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>13320.00000</td>\n",
       "      <td>3.700000e+04</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.124130</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-6.678296e+06</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>-1.100003e+05</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>50069.750000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>46973.00000</td>\n",
       "      <td>6.571900e+04</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.664456</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>26.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>99887.500000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>53703.00000</td>\n",
       "      <td>7.092500e+04</td>\n",
       "      <td>14.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.741398</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>32.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>149916.500000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.545900e+04</td>\n",
       "      <td>6.360000e+04</td>\n",
       "      <td>6.150850e+04</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>60220.00000</td>\n",
       "      <td>7.913000e+04</td>\n",
       "      <td>680.000000</td>\n",
       "      <td>1.989000e+03</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.809578</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.788800e+04</td>\n",
       "      <td>6.690000e+04</td>\n",
       "      <td>6.500000e+04</td>\n",
       "      <td>2.076000e+03</td>\n",
       "      <td>1.260000e+00</td>\n",
       "      <td>2.500000e+01</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>1.670000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>41.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>199716.000000</td>\n",
       "      <td>354.000000</td>\n",
       "      <td>144.000000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>9.652492e+07</td>\n",
       "      <td>1.000000e+09</td>\n",
       "      <td>1.000000e+09</td>\n",
       "      <td>52.000000</td>\n",
       "      <td>36.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>3.603285e+07</td>\n",
       "      <td>2.688820e+07</td>\n",
       "      <td>2.688820e+07</td>\n",
       "      <td>990572.00000</td>\n",
       "      <td>1.628992e+06</td>\n",
       "      <td>890.000000</td>\n",
       "      <td>2.076655e+07</td>\n",
       "      <td>3.246710e+06</td>\n",
       "      <td>35.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>117.000000</td>\n",
       "      <td>117.000000</td>\n",
       "      <td>28.000000</td>\n",
       "      <td>0.937987</td>\n",
       "      <td>354.000000</td>\n",
       "      <td>344.000000</td>\n",
       "      <td>42.000000</td>\n",
       "      <td>344.000000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>9.652492e+07</td>\n",
       "      <td>1.000000e+09</td>\n",
       "      <td>1.000000e+09</td>\n",
       "      <td>2.076655e+07</td>\n",
       "      <td>5.000001e+06</td>\n",
       "      <td>1.000000e+09</td>\n",
       "      <td>1.980000e+07</td>\n",
       "      <td>5.000000e+07</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>69.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         customer_id  main_account_loan_no  main_account_active_loan_no  main_account_overdue_no  main_account_outstanding_loan  main_account_sanction_loan  \\\n",
       "count  150000.000000         150000.000000                150000.000000            150000.000000                   1.500000e+05                1.500000e+05   \n",
       "mean    99944.368847              2.447133                     1.045500                 0.153427                   1.670825e+05                2.225586e+05   \n",
       "std     57629.110557              5.197172                     1.952708                 0.542496                   9.808619e+05                2.840313e+06   \n",
       "min         0.000000              0.000000                     0.000000                 0.000000                  -6.678296e+06                0.000000e+00   \n",
       "25%     50069.750000              0.000000                     0.000000                 0.000000                   0.000000e+00                0.000000e+00   \n",
       "50%     99887.500000              1.000000                     0.000000                 0.000000                   0.000000e+00                0.000000e+00   \n",
       "75%    149916.500000              3.000000                     1.000000                 0.000000                   3.545900e+04                6.360000e+04   \n",
       "max    199716.000000            354.000000                   144.000000                23.000000                   9.652492e+07                1.000000e+09   \n",
       "\n",
       "       main_account_disbursed_loan  sub_account_loan_no  sub_account_active_loan_no  sub_account_overdue_no  sub_account_outstanding_loan  sub_account_sanction_loan  \\\n",
       "count                 1.500000e+05        150000.000000               150000.000000           150000.000000                  1.500000e+05               1.500000e+05   \n",
       "mean                  2.221730e+05             0.060133                    0.027967                0.007293                  5.416077e+03               7.385876e+03   \n",
       "std                   2.844075e+06             0.652912                    0.325185                0.111236                  1.617336e+05               1.742796e+05   \n",
       "min                   0.000000e+00             0.000000                    0.000000                0.000000                 -5.746470e+05               0.000000e+00   \n",
       "25%                   0.000000e+00             0.000000                    0.000000                0.000000                  0.000000e+00               0.000000e+00   \n",
       "50%                   0.000000e+00             0.000000                    0.000000                0.000000                  0.000000e+00               0.000000e+00   \n",
       "75%                   6.150850e+04             0.000000                    0.000000                0.000000                  0.000000e+00               0.000000e+00   \n",
       "max                   1.000000e+09            52.000000                   36.000000                7.000000                  3.603285e+07               2.688820e+07   \n",
       "\n",
       "       sub_account_disbursed_loan  disbursed_amount    asset_cost   credit_score  main_account_monthly_payment  sub_account_monthly_payment  last_six_month_new_loan_no  \\\n",
       "count                1.500000e+05      150000.00000  1.500000e+05  150000.000000                  1.500000e+05                 1.500000e+05               150000.000000   \n",
       "mean                 7.268286e+03       54238.47824  7.580399e+04     291.228720                  1.295898e+04                 2.938682e+02                    0.384900   \n",
       "std                  1.735824e+05       12835.46104  1.879745e+04     339.282431                  1.508468e+05                 1.304782e+04                    0.962877   \n",
       "min                  0.000000e+00       13320.00000  3.700000e+04       0.000000                  0.000000e+00                 0.000000e+00                    0.000000   \n",
       "25%                  0.000000e+00       46973.00000  6.571900e+04       0.000000                  0.000000e+00                 0.000000e+00                    0.000000   \n",
       "50%                  0.000000e+00       53703.00000  7.092500e+04      14.000000                  0.000000e+00                 0.000000e+00                    0.000000   \n",
       "75%                  0.000000e+00       60220.00000  7.913000e+04     680.000000                  1.989000e+03                 0.000000e+00                    0.000000   \n",
       "max                  2.688820e+07      990572.00000  1.628992e+06     890.000000                  2.076655e+07                 3.246710e+06                   35.000000   \n",
       "\n",
       "       last_six_month_defaulted_no    average_age  credit_history    enquirie_no  loan_to_asset_ratio  total_account_loan_no  sub_account_inactive_loan_no  \\\n",
       "count                150000.000000  150000.000000   150000.000000  150000.000000        150000.000000          150000.000000                 150000.000000   \n",
       "mean                      0.095687       8.027107       13.128353       0.203433             0.723558               2.507267                      1.401633   \n",
       "std                       0.382359      13.830386       21.125146       0.696590             0.113621               5.273201                      3.924056   \n",
       "min                       0.000000       0.000000        0.000000       0.000000             0.124130               0.000000                      0.000000   \n",
       "25%                       0.000000       0.000000        0.000000       0.000000             0.664456               0.000000                      0.000000   \n",
       "50%                       0.000000       0.000000        0.000000       0.000000             0.741398               1.000000                      0.000000   \n",
       "75%                       0.000000      13.000000       20.000000       0.000000             0.809578               3.000000                      1.000000   \n",
       "max                      20.000000     117.000000      117.000000      28.000000             0.937987             354.000000                    344.000000   \n",
       "\n",
       "       total_inactive_loan_no  main_account_inactive_loan_no  total_overdue_no  total_outstanding_loan  total_sanction_loan  total_disbursed_loan  total_monthly_payment  \\\n",
       "count           150000.000000                  150000.000000     150000.000000            1.500000e+05         1.500000e+05          1.500000e+05           1.500000e+05   \n",
       "mean                 0.032167                       1.433800          0.160720            1.724986e+05         2.299445e+05          2.294413e+05           1.325285e+04   \n",
       "std                  0.429154                       3.964609          0.557779            9.969156e+05         2.847267e+06          2.850957e+06           1.515095e+05   \n",
       "min                  0.000000                       0.000000          0.000000           -6.678296e+06         0.000000e+00          0.000000e+00           0.000000e+00   \n",
       "25%                  0.000000                       0.000000          0.000000            0.000000e+00         0.000000e+00          0.000000e+00           0.000000e+00   \n",
       "50%                  0.000000                       0.000000          0.000000            0.000000e+00         0.000000e+00          0.000000e+00           0.000000e+00   \n",
       "75%                  0.000000                       1.000000          0.000000            3.788800e+04         6.690000e+04          6.500000e+04           2.076000e+03   \n",
       "max                 42.000000                     344.000000         23.000000            9.652492e+07         1.000000e+09          1.000000e+09           2.076655e+07   \n",
       "\n",
       "       outstanding_disburse_ratio  main_account_tenure  sub_account_tenure  disburse_to_sactioned_ratio  active_to_inactive_act_ratio   Credit_level            age   loan_default  \n",
       "count                1.499880e+05         1.500000e+05        1.500000e+05                 1.500000e+05                 150000.000000  150000.000000  150000.000000  150000.000000  \n",
       "mean                 1.391973e+03         5.169842e+04        2.773138e+03                 6.506428e+02                      1.438740       3.132360      34.132100       0.176967  \n",
       "std                  3.132484e+04         2.614563e+06        1.043622e+05                 1.312314e+05                      0.789844       5.268384       9.813379       0.381642  \n",
       "min                 -1.100003e+05         0.000000e+00        0.000000e+00                 0.000000e+00                      1.000000      -1.000000      18.000000       0.000000  \n",
       "25%                  1.000000e+00         0.000000e+00        0.000000e+00                 1.000000e+00                      1.000000      -1.000000      26.000000       0.000000  \n",
       "50%                  1.000000e+00         0.000000e+00        0.000000e+00                 1.000000e+00                      1.000000      -1.000000      32.000000       0.000000  \n",
       "75%                  1.260000e+00         2.500000e+01        0.000000e+00                 1.000000e+00                      1.670000       8.000000      41.000000       0.000000  \n",
       "max                  5.000001e+06         1.000000e+09        1.980000e+07                 5.000000e+07                     18.000000      13.000000      69.000000       1.000000  "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=3 fonc=\"仿宋\" color=green>（四）特征合并</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T17:16:55.136245Z",
     "start_time": "2021-07-15T17:16:54.157206Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 966 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "train = train.join(train_onehot)\n",
    "train.index = range(len(train))\n",
    "\n",
    "test = test.join(train_onehot)\n",
    "test.index = range(len(test))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=5 color=blue fonc=\"仿宋\">五、建模</font>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=3 fonc=\"仿宋\" color=green>（一）划分变量与目标</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T17:17:09.676040Z",
     "start_time": "2021-07-15T17:17:09.398025Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 273 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "# loan_default = train.pop('loan_default')\n",
    "feature = train.iloc[:, 1:]\n",
    "\n",
    "uid = test.customer_id\n",
    "pred_feature = test.iloc[:, 1:]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=3 fonc=\"仿宋\" color=green>（二）划分训练集与测试集</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T17:17:16.208327Z",
     "start_time": "2021-07-15T17:17:14.057221Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 2.14 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "x_train, x_test, y_train, y_test = train_test_split(feature, label, \n",
    "                                                    test_size=0.4, \n",
    "                                                    random_state=2021)\n",
    "x_valid, x_test, y_valid, y_test = train_test_split(x_test, y_test, \n",
    "                                                    test_size=0.5, \n",
    "                                                    random_state=2021)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=3 fonc=\"仿宋\" color=green>（三）baseline版本</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T17:18:19.844378Z",
     "start_time": "2021-07-15T17:17:35.874421Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1]\ttraining's binary_logloss: 0.46344\ttraining's auc: 0.627071\tvalid_1's binary_logloss: 0.465407\tvalid_1's auc: 0.619534\n",
      "Training until validation scores don't improve for 10 rounds\n",
      "[2]\ttraining's binary_logloss: 0.461081\ttraining's auc: 0.631891\tvalid_1's binary_logloss: 0.463322\tvalid_1's auc: 0.621237\n",
      "[3]\ttraining's binary_logloss: 0.45909\ttraining's auc: 0.637247\tvalid_1's binary_logloss: 0.461514\tvalid_1's auc: 0.626419\n",
      "[4]\ttraining's binary_logloss: 0.457362\ttraining's auc: 0.640121\tvalid_1's binary_logloss: 0.460081\tvalid_1's auc: 0.627084\n",
      "[5]\ttraining's binary_logloss: 0.455802\ttraining's auc: 0.642416\tvalid_1's binary_logloss: 0.458686\tvalid_1's auc: 0.629004\n",
      "[6]\ttraining's binary_logloss: 0.45446\ttraining's auc: 0.644199\tvalid_1's binary_logloss: 0.457617\tvalid_1's auc: 0.630363\n",
      "[7]\ttraining's binary_logloss: 0.453301\ttraining's auc: 0.645976\tvalid_1's binary_logloss: 0.456725\tvalid_1's auc: 0.630835\n",
      "[8]\ttraining's binary_logloss: 0.452229\ttraining's auc: 0.647669\tvalid_1's binary_logloss: 0.455889\tvalid_1's auc: 0.63202\n",
      "[9]\ttraining's binary_logloss: 0.45132\ttraining's auc: 0.649418\tvalid_1's binary_logloss: 0.455241\tvalid_1's auc: 0.632773\n",
      "[10]\ttraining's binary_logloss: 0.450428\ttraining's auc: 0.651365\tvalid_1's binary_logloss: 0.454621\tvalid_1's auc: 0.633903\n",
      "[11]\ttraining's binary_logloss: 0.44964\ttraining's auc: 0.65254\tvalid_1's binary_logloss: 0.454027\tvalid_1's auc: 0.635116\n",
      "[12]\ttraining's binary_logloss: 0.448903\ttraining's auc: 0.653864\tvalid_1's binary_logloss: 0.453449\tvalid_1's auc: 0.636053\n",
      "[13]\ttraining's binary_logloss: 0.448105\ttraining's auc: 0.655802\tvalid_1's binary_logloss: 0.45282\tvalid_1's auc: 0.637842\n",
      "[14]\ttraining's binary_logloss: 0.447471\ttraining's auc: 0.656967\tvalid_1's binary_logloss: 0.452352\tvalid_1's auc: 0.638629\n",
      "[15]\ttraining's binary_logloss: 0.446867\ttraining's auc: 0.657993\tvalid_1's binary_logloss: 0.451937\tvalid_1's auc: 0.639525\n",
      "[16]\ttraining's binary_logloss: 0.446273\ttraining's auc: 0.659442\tvalid_1's binary_logloss: 0.451492\tvalid_1's auc: 0.640805\n",
      "[17]\ttraining's binary_logloss: 0.445622\ttraining's auc: 0.660997\tvalid_1's binary_logloss: 0.451074\tvalid_1's auc: 0.641653\n",
      "[18]\ttraining's binary_logloss: 0.445091\ttraining's auc: 0.662189\tvalid_1's binary_logloss: 0.450828\tvalid_1's auc: 0.641871\n",
      "[19]\ttraining's binary_logloss: 0.444602\ttraining's auc: 0.663321\tvalid_1's binary_logloss: 0.45062\tvalid_1's auc: 0.642255\n",
      "[20]\ttraining's binary_logloss: 0.444046\ttraining's auc: 0.664578\tvalid_1's binary_logloss: 0.450355\tvalid_1's auc: 0.642666\n",
      "[21]\ttraining's binary_logloss: 0.443518\ttraining's auc: 0.665734\tvalid_1's binary_logloss: 0.450016\tvalid_1's auc: 0.643354\n",
      "[22]\ttraining's binary_logloss: 0.443023\ttraining's auc: 0.666664\tvalid_1's binary_logloss: 0.449735\tvalid_1's auc: 0.643885\n",
      "[23]\ttraining's binary_logloss: 0.442548\ttraining's auc: 0.667657\tvalid_1's binary_logloss: 0.449531\tvalid_1's auc: 0.644273\n",
      "[24]\ttraining's binary_logloss: 0.442101\ttraining's auc: 0.668798\tvalid_1's binary_logloss: 0.44928\tvalid_1's auc: 0.644862\n",
      "[25]\ttraining's binary_logloss: 0.44166\ttraining's auc: 0.669855\tvalid_1's binary_logloss: 0.44907\tvalid_1's auc: 0.64531\n",
      "[26]\ttraining's binary_logloss: 0.441229\ttraining's auc: 0.670909\tvalid_1's binary_logloss: 0.44894\tvalid_1's auc: 0.645546\n",
      "[27]\ttraining's binary_logloss: 0.440832\ttraining's auc: 0.671961\tvalid_1's binary_logloss: 0.4488\tvalid_1's auc: 0.64587\n",
      "[28]\ttraining's binary_logloss: 0.440462\ttraining's auc: 0.672937\tvalid_1's binary_logloss: 0.448779\tvalid_1's auc: 0.645743\n",
      "[29]\ttraining's binary_logloss: 0.440105\ttraining's auc: 0.673649\tvalid_1's binary_logloss: 0.448663\tvalid_1's auc: 0.646018\n",
      "[30]\ttraining's binary_logloss: 0.439727\ttraining's auc: 0.674568\tvalid_1's binary_logloss: 0.448528\tvalid_1's auc: 0.646338\n",
      "[31]\ttraining's binary_logloss: 0.439412\ttraining's auc: 0.67528\tvalid_1's binary_logloss: 0.448454\tvalid_1's auc: 0.646397\n",
      "[32]\ttraining's binary_logloss: 0.43908\ttraining's auc: 0.676218\tvalid_1's binary_logloss: 0.448414\tvalid_1's auc: 0.646511\n",
      "[33]\ttraining's binary_logloss: 0.438749\ttraining's auc: 0.677244\tvalid_1's binary_logloss: 0.448411\tvalid_1's auc: 0.646309\n",
      "[34]\ttraining's binary_logloss: 0.438437\ttraining's auc: 0.677882\tvalid_1's binary_logloss: 0.448335\tvalid_1's auc: 0.646252\n",
      "[35]\ttraining's binary_logloss: 0.438094\ttraining's auc: 0.678793\tvalid_1's binary_logloss: 0.448296\tvalid_1's auc: 0.646332\n",
      "[36]\ttraining's binary_logloss: 0.437783\ttraining's auc: 0.679545\tvalid_1's binary_logloss: 0.448251\tvalid_1's auc: 0.646328\n",
      "[37]\ttraining's binary_logloss: 0.437495\ttraining's auc: 0.680224\tvalid_1's binary_logloss: 0.448177\tvalid_1's auc: 0.6465\n",
      "[38]\ttraining's binary_logloss: 0.437184\ttraining's auc: 0.681156\tvalid_1's binary_logloss: 0.448159\tvalid_1's auc: 0.646524\n",
      "[39]\ttraining's binary_logloss: 0.436901\ttraining's auc: 0.681999\tvalid_1's binary_logloss: 0.448071\tvalid_1's auc: 0.646769\n",
      "[40]\ttraining's binary_logloss: 0.436625\ttraining's auc: 0.682589\tvalid_1's binary_logloss: 0.447968\tvalid_1's auc: 0.647163\n",
      "[41]\ttraining's binary_logloss: 0.436333\ttraining's auc: 0.683379\tvalid_1's binary_logloss: 0.44796\tvalid_1's auc: 0.647235\n",
      "[42]\ttraining's binary_logloss: 0.436065\ttraining's auc: 0.684206\tvalid_1's binary_logloss: 0.447924\tvalid_1's auc: 0.64739\n",
      "[43]\ttraining's binary_logloss: 0.43582\ttraining's auc: 0.684684\tvalid_1's binary_logloss: 0.447917\tvalid_1's auc: 0.647254\n",
      "[44]\ttraining's binary_logloss: 0.435576\ttraining's auc: 0.685385\tvalid_1's binary_logloss: 0.447909\tvalid_1's auc: 0.647309\n",
      "[45]\ttraining's binary_logloss: 0.435312\ttraining's auc: 0.68614\tvalid_1's binary_logloss: 0.447861\tvalid_1's auc: 0.647496\n",
      "[46]\ttraining's binary_logloss: 0.435064\ttraining's auc: 0.686881\tvalid_1's binary_logloss: 0.447818\tvalid_1's auc: 0.647635\n",
      "[47]\ttraining's binary_logloss: 0.434806\ttraining's auc: 0.68748\tvalid_1's binary_logloss: 0.447824\tvalid_1's auc: 0.647636\n",
      "[48]\ttraining's binary_logloss: 0.434577\ttraining's auc: 0.687967\tvalid_1's binary_logloss: 0.44781\tvalid_1's auc: 0.647701\n",
      "[49]\ttraining's binary_logloss: 0.434349\ttraining's auc: 0.68861\tvalid_1's binary_logloss: 0.447805\tvalid_1's auc: 0.647655\n",
      "[50]\ttraining's binary_logloss: 0.434107\ttraining's auc: 0.689228\tvalid_1's binary_logloss: 0.447734\tvalid_1's auc: 0.647972\n",
      "[51]\ttraining's binary_logloss: 0.433874\ttraining's auc: 0.689892\tvalid_1's binary_logloss: 0.447696\tvalid_1's auc: 0.648085\n",
      "[52]\ttraining's binary_logloss: 0.43365\ttraining's auc: 0.690528\tvalid_1's binary_logloss: 0.447677\tvalid_1's auc: 0.648125\n",
      "[53]\ttraining's binary_logloss: 0.433383\ttraining's auc: 0.691378\tvalid_1's binary_logloss: 0.447676\tvalid_1's auc: 0.648157\n",
      "[54]\ttraining's binary_logloss: 0.433172\ttraining's auc: 0.691976\tvalid_1's binary_logloss: 0.447643\tvalid_1's auc: 0.648223\n",
      "[55]\ttraining's binary_logloss: 0.432955\ttraining's auc: 0.692465\tvalid_1's binary_logloss: 0.44763\tvalid_1's auc: 0.648262\n",
      "[56]\ttraining's binary_logloss: 0.432703\ttraining's auc: 0.69303\tvalid_1's binary_logloss: 0.447603\tvalid_1's auc: 0.648321\n",
      "[57]\ttraining's binary_logloss: 0.432422\ttraining's auc: 0.693777\tvalid_1's binary_logloss: 0.447537\tvalid_1's auc: 0.648525\n",
      "[58]\ttraining's binary_logloss: 0.432185\ttraining's auc: 0.694484\tvalid_1's binary_logloss: 0.447548\tvalid_1's auc: 0.648462\n",
      "[59]\ttraining's binary_logloss: 0.431953\ttraining's auc: 0.695282\tvalid_1's binary_logloss: 0.447536\tvalid_1's auc: 0.648607\n",
      "[60]\ttraining's binary_logloss: 0.431706\ttraining's auc: 0.696104\tvalid_1's binary_logloss: 0.447468\tvalid_1's auc: 0.648839\n",
      "[61]\ttraining's binary_logloss: 0.431503\ttraining's auc: 0.696607\tvalid_1's binary_logloss: 0.447479\tvalid_1's auc: 0.648798\n",
      "[62]\ttraining's binary_logloss: 0.431301\ttraining's auc: 0.697134\tvalid_1's binary_logloss: 0.447458\tvalid_1's auc: 0.648928\n",
      "[63]\ttraining's binary_logloss: 0.431042\ttraining's auc: 0.697985\tvalid_1's binary_logloss: 0.447392\tvalid_1's auc: 0.649158\n",
      "[64]\ttraining's binary_logloss: 0.430841\ttraining's auc: 0.698584\tvalid_1's binary_logloss: 0.447355\tvalid_1's auc: 0.649327\n",
      "[65]\ttraining's binary_logloss: 0.43065\ttraining's auc: 0.699169\tvalid_1's binary_logloss: 0.447362\tvalid_1's auc: 0.649265\n",
      "[66]\ttraining's binary_logloss: 0.430435\ttraining's auc: 0.699887\tvalid_1's binary_logloss: 0.447324\tvalid_1's auc: 0.6495\n",
      "[67]\ttraining's binary_logloss: 0.430208\ttraining's auc: 0.700563\tvalid_1's binary_logloss: 0.447286\tvalid_1's auc: 0.649634\n",
      "[68]\ttraining's binary_logloss: 0.429982\ttraining's auc: 0.701185\tvalid_1's binary_logloss: 0.447331\tvalid_1's auc: 0.649507\n",
      "[69]\ttraining's binary_logloss: 0.429765\ttraining's auc: 0.701887\tvalid_1's binary_logloss: 0.447358\tvalid_1's auc: 0.64945\n",
      "[70]\ttraining's binary_logloss: 0.429553\ttraining's auc: 0.702508\tvalid_1's binary_logloss: 0.447354\tvalid_1's auc: 0.649474\n",
      "[71]\ttraining's binary_logloss: 0.429377\ttraining's auc: 0.703102\tvalid_1's binary_logloss: 0.447326\tvalid_1's auc: 0.649557\n",
      "[72]\ttraining's binary_logloss: 0.429176\ttraining's auc: 0.703498\tvalid_1's binary_logloss: 0.447325\tvalid_1's auc: 0.649611\n",
      "[73]\ttraining's binary_logloss: 0.428972\ttraining's auc: 0.704096\tvalid_1's binary_logloss: 0.447333\tvalid_1's auc: 0.649562\n",
      "[74]\ttraining's binary_logloss: 0.428797\ttraining's auc: 0.704733\tvalid_1's binary_logloss: 0.447354\tvalid_1's auc: 0.649503\n",
      "[75]\ttraining's binary_logloss: 0.428584\ttraining's auc: 0.705406\tvalid_1's binary_logloss: 0.447328\tvalid_1's auc: 0.649637\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[76]\ttraining's binary_logloss: 0.428391\ttraining's auc: 0.705788\tvalid_1's binary_logloss: 0.447302\tvalid_1's auc: 0.649688\n",
      "[77]\ttraining's binary_logloss: 0.428219\ttraining's auc: 0.706318\tvalid_1's binary_logloss: 0.447331\tvalid_1's auc: 0.649578\n",
      "Early stopping, best iteration is:\n",
      "[67]\ttraining's binary_logloss: 0.430208\ttraining's auc: 0.700563\tvalid_1's binary_logloss: 0.447286\tvalid_1's auc: 0.649634\n",
      "Wall time: 44 s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "LGBMClassifier()"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "model = LGBMClassifier()\n",
    "model.fit(x_train, y_train, \n",
    "          early_stopping_rounds=10, \n",
    "          eval_metric=[\"logloss\", \"auc\"], \n",
    "          eval_set=[(x_train, y_train), (x_valid, y_valid)], \n",
    "          verbose=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=3 fonc=\"仿宋\" color=green>（四）baseline评估</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T17:18:47.399626Z",
     "start_time": "2021-07-15T17:18:47.208618Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "模型得分： 0.45500472861530694\n",
      "混淆矩阵：\n",
      "               precision    recall  f1-score   support\n",
      "\n",
      "           0       0.82      1.00      0.90     24690\n",
      "           1       0.54      0.00      0.01      5310\n",
      "\n",
      "    accuracy                           0.82     30000\n",
      "   macro avg       0.68      0.50      0.46     30000\n",
      "weighted avg       0.77      0.82      0.74     30000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "pred = model.predict(x_test)\n",
    "print(\"模型得分：\", f1_score(y_test, pred, average=\"macro\"))\n",
    "print(\"混淆矩阵：\\n\", classification_report(y_test, pred))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-15T17:07:18.507232Z",
     "start_time": "2021-07-15T17:07:18.266225Z"
    }
   },
   "outputs": [],
   "source": [
    "test['loan_default'] = model.predict(pred_feature)\n",
    "test[['customer_id', 'loan_default']].to_csv('result.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:lkm]",
   "language": "python",
   "name": "lkm"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
